package 
{
	import flash.display.MovieClip;
	
	import org.osmf.containers.MediaContainer;
	import org.osmf.elements.ParallelElement;
	import org.osmf.layout.HorizontalAlign;
	import org.osmf.layout.LayoutMetadata;
	import org.osmf.layout.LayoutMode;
	import org.osmf.layout.ScaleMode;
	import org.osmf.layout.VerticalAlign;
	import org.osmf.media.DefaultMediaFactory;
	import org.osmf.media.MediaElement;
	import org.osmf.media.MediaPlayer;
	
	//Sets the size of the SWF
	
	[SWF(width="800", height="600")]
	public class WT06_BasicParallelComposition extends MovieClip
	{
		import org.osmf.elements.VideoElement;
		import org.osmf.media.URLResource;
		import org.osmf.utils.URL;
		
		////////////////////////////////////////////////////
		//DECLARATIONS
		////////////////////////////////////////////////////
		
		//URI of the media
		public static const PROGRESSIVE_PATH:String = "http://mediapm.edgesuite.net/strobe/content/test/AFaerysTale_sylviaApostol_640_500_short.flv";
		public static const STREAMING_PATH:String = "rtmp://cp67126.edgefcs.net/ondemand/mediapm/osmf/content/test/akamai_10_year_f8_512K";
		public static const STREAMING_MP4_PATH:String = "rtmp://cp67126.edgefcs.net/ondemand/mp4:mediapm/ovp/content/demo/video/elephants_dream/elephants_dream_768x428_24.0fps_408kbps.mp4";
		public static const LOCAL_SWF:String = "assets/swf_banner.swf";
		public static const DYNAMIC_STREAMING:String = "http://mediapm.edgesuite.net/osmf/content/test/manifest-files/dynamic_Streaming.f4m";
		public static const LOGO_VID:String = "http://mediapm.edgesuite.net/osmf/content/test/logo_animated.flv";
		
		public var player:MediaPlayer;
		public var container:MediaContainer;
		public var mediaFactory:DefaultMediaFactory;
		
		////////////////////////////////////////////////////
		//CONSTRUCTOR
		////////////////////////////////////////////////////
		
		public function WT06_BasicParallelComposition()
		{
			//stage.scaleMode = StageScaleMode.NO_SCALE;
			//stage.align = StageAlign.TOP_LEFT;
			
			
			initPlayer();
		}
		
		
		
		
		protected function initPlayer():void
		{
			// Create a mediafactory instance
			mediaFactory = new DefaultMediaFactory();
			
			//Marker 1: Create a LayoutMetaData object stup up to even out the 2 parellel streams initially
			var layoutData:LayoutMetadata = new LayoutMetadata();
			layoutData.percentWidth = 50;
			layoutData.percentHeight = 50;
			layoutData.scaleMode = ScaleMode.LETTERBOX;
			
			//Marker 2: Create the left side Media Element to play the LOGO_VID and apply the meta-data
			var leftElement:MediaElement = mediaFactory.createMediaElement( new URLResource( LOGO_VID ) );
			leftElement.metadata.addValue( LayoutMetadata.LAYOUT_NAMESPACE, layoutData );
			
			//Marker 3: Create the right side Media Element to play the STREAMING_PATH and apply the meta-data
			var rightElement:MediaElement = mediaFactory.createMediaElement( new URLResource( STREAMING_PATH ) );
			rightElement.metadata.addValue( LayoutMetadata.LAYOUT_NAMESPACE, layoutData );			
			
			//Marker 4: Create the ParallelElement and add the left and right elements to it
			var parallelElement:ParallelElement = new ParallelElement();
			parallelElement.addChild( leftElement );
			parallelElement.addChild( rightElement );
			
			//Marker 5: Reinstantiate the layoutData to clear it out and set the layout data for the parallel element
			layoutData = new LayoutMetadata();
			layoutData.layoutMode = LayoutMode.HORIZONTAL;
			layoutData.horizontalAlign = HorizontalAlign.CENTER;
			layoutData.verticalAlign = VerticalAlign.MIDDLE;
			layoutData.width = 800;
			layoutData.height = 600;
			parallelElement.metadata.addValue( LayoutMetadata.LAYOUT_NAMESPACE, layoutData );
			
			//the simplified api controller for media
			player = new MediaPlayer( parallelElement );
			
			//the container (sprite) for managing display and layout
			container = new MediaContainer();
			container.addMediaElement( parallelElement );
			
			
			//Adds the container to the stage
			this.addChild( container );
		}
		
		
	}
}